<template>
  <div class="index">
    <Loading
      v-if="
        bannerImgs.length == 0 ||
          info == {} ||
          gridList.length == 0 ||
          notice.length == 0 ||
          likeInfo.length == 0 ||
          benefit.length == 0
      "
    ></Loading>

    <div class="top">
      <div class="logo">
        <img
          src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fgss0.baidu.com%2F-Po3dSag_xI4khGko9WTAnF6hhy%2Fzhidao%2Fpic%2Fitem%2Fcefc1e178a82b901f1c5b0e4718da9773812eff9.jpg&refer=http%3A%2F%2Fgss0.baidu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1617192732&t=6e6f111c5b4be359af300e79f00f9a9e"
        />
      </div>
      <router-link to="/search" class="search">
        <span class="iconfont"></span>搜索商品
      </router-link>
    </div>

    <!-- banner轮播图 -->
    <van-swipe
      ref="indexBanner"
      autoplay="5000"
      duration="500"
      indicator-color="red"
      class="my-swipe"
    >
      <van-swipe-item v-for="i in bannerImgs" :key="i.id">
        <router-link to="/">
          <van-image :src="i.pic" />
        </router-link>
      </van-swipe-item>
    </van-swipe>

    <van-grid column-num="4">
      <van-grid-item v-for="i in gridList" :key="i.id">
        <router-link :to="i.wap_url + `?path=${i.wap_url}`">
          <van-image :src="i.pic" />
          <p class="itemName">{{ i.name }}</p>
        </router-link>
      </van-grid-item>
    </van-grid>

    <!-- noticeBar -->
    <van-notice-bar
      left-icon="phone"
      :scrollable="false"
      class="noticeBar"
      mode="link"
    >
      <template v-slot:left-icon>
        <van-image
          class="notice-left-icon left"
          fit="contain"
          src=""
        />
      </template>

      <template v-slot:default>
        <van-swipe
          vertical
          :autoplay="3000"
          :show-indicators="false"
          class="notice-swipe"
        >
          <van-swipe-item v-for="i in notice" :key="i.id">
            <router-link to="/news_list">
              {{ i.info }}
            </router-link>
          </van-swipe-item>
        </van-swipe>
      </template>
    </van-notice-bar>

    <div class="wrapper">
      <div class="wrapperTitle">
        <div class="name line1">快速选择</div>
        <div class="line1">{{ info.fastInfo }}</div>
        <router-link to="/category" tag="div" class="more">
          <span>更多</span>
          <van-icon name="arrow" />
        </router-link>
      </div>

      <div class="fastBanner">
        <ul class="fastList">
          <li v-for="i in info.fastList" :key="i.id">
            <router-link
              :to="'/goods_list' + `?title=${i.cate_name}&uid=${i.id}`"
            >
              <img :src="i.pic" />
              <p>{{ i.cate_name }}</p>
            </router-link>
          </li>
        </ul>
      </div>
    </div>

    <div class="wrapper">
      <div class="wrapperTitle">
        <div class="name line1">精品推荐</div>
        <div class="line1">{{ info.bastInfo }}</div>
        <router-link to="/recommend/1" tag="div" class="more">
          <span>更多</span>
          <van-icon name="arrow" />
        </router-link>
      </div>
      <Bast :item="info"></Bast>
    </div>

    <div class="hotList">
      <div class="title">
        <h3>
          热门榜单<span>根据销量、搜索、好评等综合得出</span>
          <router-link to="/recommend/2" class="more">
            <span>更多</span>
            <van-icon name="arrow" />
          </router-link>
        </h3>
      </div>
      <div class="list">
        <div class="sb" v-for="(s, index) in likeInfo" :key="index">
          <router-link :to="`/detail/${s.id}`">
            <van-image class="itemImg" :src="s.image">
              <img class="ranking" :src="likeImg[index]" alt="" />
              <p>{{ s.store_name }}</p>
              <span class="num">￥{{ s.price }}</span>
            </van-image>
          </router-link>
        </div>
      </div>
    </div>

    <div class="wrapper">
      <div class="wrapperTitle">
        <div class="name line1">首发新品<span class="new">NEW~</span></div>
        <div class="line1">{{ info.firstInfo }}</div>
        <router-link to="/recommend/3" tag="div" class="more">
          <span>更多</span>
          <van-icon name="arrow" />
        </router-link>
      </div>

      <div class="firstBanner">
        <ul class="firstList">
          <li v-for="i in info.firstList" :key="i.id">
            <router-link :to="`/detail/${i.id}`">
              <van-image :src="i.image" />
              <p>{{ i.store_name }}</p>
              <span>￥{{ i.price }}</span>
            </router-link>
          </li>
        </ul>
      </div>
    </div>

    <div class="wrapper">
      <div class="wrapperTitle">
        <div class="name line1">促销单品</div>
        <div class="line1">库存商品优惠促销活动</div>
        <router-link to="/promotion" tag="div" class="more">
          <span>更多</span>
          <van-icon name="arrow" />
        </router-link>
      </div>

      <div class="benefit">
        <div v-for="l in benefit" class="item" :key="l.id">
          <router-link :to="`/detail/${l.id}`">
            <van-image :src="l.image" alt="" />
            <div class="right">
              <p class="text">{{ l.store_name }}</p>
              <div class="pri">
                <span>促销价：￥{{ l.price }}</span>
              </div>
              <div class="del">
                <div class="money">日常价：￥{{ l.ot_price }}</div>
                <div class="residue">仅剩：{{ l.stock }}{{ l.unit_name }}</div>
              </div>
            </div>
          </router-link>
        </div>
      </div>
    </div>
    <ButtomTab></ButtomTab>
  </div>
</template>

<script>
import Bast from "../components/Bast";
import ButtomTab from "@/components/ButtomTab";
import Loading from "@/components/Loading";
export default {
  name: "Index",
  data() {
    return {
      bannerIndex: 0,
      bannerImgs: [],
      gridList: [],
      notice: [],
      info: {},
      likeInfo: [],
      likeImg: [
        "http://47.115.51.185/h5/img/one.2814de22.png",
        "http://47.115.51.185/h5/img/two.1ea1d146.png",
        "http://47.115.51.185/h5/img/three.2162defb.png"
      ],
      benefit: []
    };
  },
  components: {
    Bast,
    ButtomTab,
    Loading
  },
  created() {
    this.$axios.get("/api/index").then(d => {
      this.bannerImgs = d.data.data.banner;
      this.gridList = d.data.data.menus;
      this.notice = d.data.data.roll;
      this.info = d.data.data.info;
      this.likeInfo = d.data.data.likeInfo;
      this.benefit = d.data.data.benefit;
    });
  },
  methods: {}
};
</script>
<style scoped lang="less">
.loading {
  width: 100vw;
  height: 100%;
  background: rgb(230, 230, 230);
  position: fixed;
  z-index: 50;
  line-height: 100vh;
}
.benefit {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 10px;
  box-sizing: border-box;
  .item {
    padding: 0;
    margin: 0;
    a {
      width: 100%;
      height: 4rem;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      margin: 5px 0;
      border-bottom: 1px solid rgb(220, 220, 220);
    }
    .van-image {
      width: 3rem;
      height: 3rem;
      margin-left: 10px;
    }
    .right {
      flex: 1;
      height: 3rem;
      margin-left: 10px;
      margin-right: 10px;
      .text {
        font-size: 0.4rem;
        color: rgb(51, 51, 51);
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
        text-align: left;
      }
      .pri {
        text-align: left;
        margin: 1rem 0 0.3rem 0;
        height: 0.5rem;
        span {
          display: inline-block;
          height: 0.5rem;
          padding: 0 10px;
          font-size: 0.3rem;
          background: rgb(255, 75, 45);
          color: white;
          line-height: 0.5rem;
          border-top-left-radius: 12px;
          border-bottom-right-radius: 12px;
        }
      }
      .del {
        color: #999;
        overflow: hidden;
        font-size: 0.3rem;
        .money {
          text-decoration: line-through;
          float: left;
        }
        .residue {
          float: right;
        }
      }
    }
  }
}
.firstBanner {
  margin: 0 10px;
  overflow-x: scroll;
  border-bottom: 1px solid rgb(238, 238, 238);
  &::-webkit-scrollbar {
    display: none;
  }
  .firstList {
    display: flex;
    justify-content: flex-start;
    margin-top: 10px;
    li {
      width: 100%;
      margin: 5px;
      .van-image {
        width: 3rem;
        height: 3rem;
        border-radius: 10px;
        overflow: hidden;
        border: 1px rgb(238, 238, 238) solid;
      }
      p {
        font-size: 0.4rem;
        color: rgb(51, 51, 51);
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
        text-align: left;
      }
      span {
        color: red;
        font-size: 0.35rem;
        font-weight: bold;
      }
    }
  }
}

.hotList {
  width: 100%;

  .title {
    width: 100%;
    height: 3rem;
    background: url("../assets/hotBg.png");
    background-size: 100%;
    background-repeat: no-repeat;
    padding: 0 0.4rem;
    box-sizing: border-box;
    h3 {
      line-height: 1rem;
      text-align: left;
      font-weight: bold;
      font-size: 0.4rem;
      color: white;
      position: relative;
      span {
        margin-left: 0.3rem;
        font-weight: normal;
        font-size: 0.3rem;
      }
      .more {
        position: absolute;
        right: 0.25rem;
        top: 50%;
        transform: translateY(-50%);
        color: white;
        font-size: 0.35rem;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        span {
          font-size: 0.35rem;
          // margin-right: 0.1rem;
          cursor: pointer;
        }
      }
    }
  }
  .list {
    width: 95%;
    height: 4.7rem;
    margin: 0 auto;
    background: white;
    margin-top: -2rem;
    border-radius: 10px;
    box-shadow: 0 1px 0px rgb(200, 200, 200);
    display: flex;
    justify-content: flex-start;
    div.sb {
      width: 33%;
      height: 3.5rem;
    }
    .van-image {
      width: 3rem;
      margin: 5px;
      height: 3rem;
      position: relative;
      .ranking {
        position: absolute;
        width: 0.6rem;
        height: 0.6rem;
        left: 0.1rem;
        top: 0.1rem;
        background-size: 100%;
      }
      .van-image__img {
        width: 100%;
        height: auto;
      }
      p {
        text-align: left;
        font-size: 0.4rem;
        margin-top: 10px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
        color: rgb(51, 51, 51);
      }
      .num {
        color: red;
        font-size: 0.35rem;
        text-align: left;
        display: block;
        margin-top: 5px;
        font-weight: bold;
      }
    }
  }
}
a {
  text-decoration: none;
}
.wrapper {
  width: 100vw;
  overflow: hidden;
  margin-top: 10px;
  background-color: white;
  .wrapperTitle {
    width: 100%;
    position: relative;
    margin-left: 10px;
    .line1 {
      font-size: 0.4rem;
      color: #999;
      width: 15rem;
      text-align: left;
      margin-left: 10px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      overflow: hidden;
      .new {
        font-size: 0.2rem;
        color: red;
        vertical-align: top;
        margin-left: 0.2rem;
      }
    }
    .name {
      font-weight: bolder;
      font-size: 0.5rem;
      color: rgb(40, 40, 40);
      margin: 5px 0;
      margin-left: 10px;
    }
    .more {
      position: absolute;
      right: 0.25rem;
      top: 50%;
      transform: translateY(-50%);
      color: rgb(51, 51, 51);
      font-size: 0.45rem;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      span {
        // margin-right: 0.1rem;
        cursor: pointer;
      }
    }
  }
  .fastBanner {
    margin: 0 10px;
    overflow-x: scroll;
    border-bottom: 1px solid rgb(238, 238, 238);
    &::-webkit-scrollbar {
      display: none;
    }
    .fastList {
      display: flex;
      justify-content: flex-start;
      margin-top: 10px;
      li {
        width: 100%;
        border: 1px rgb(238, 238, 238) solid;
        margin: 5px;
        margin-bottom: 20px;
        &:nth-child(3n + 1) {
          border-bottom: 2px rgb(71, 180, 121) solid;
        }
        &:nth-child(3n + 2) {
          border-bottom: 2px rgb(87, 154, 254) solid;
        }
        &:nth-child(3n + 3) {
          border-bottom: 2px rgb(255, 105, 96) solid;
        }
        img {
          width: 2.8rem;
          height: auto;
        }
        p {
          font-size: 0.4rem;
          color: rgb(51, 51, 51);
        }
      }
    }
  }
}

.my-swipe {
  width: 100vw;
  background: white;
  .van-swipe__track {
    width: 100%;
    .van-swipe-item {
      width: 100%;
      a {
        display: block;
        width: 100%;
        .van-image {
          width: 100%;

          img {
            width: 100%;
            // height: auto;
          }
        }
      }
    }
  }
}

.banner_indicator {
  position: absolute;
  right: 0px;
  bottom: 10px;
  padding: 5px;
  color: white;
  background-color: rgba(0, 0, 0, 0.5);
}
.van-grid-item__content {
  .van-image {
    width: 1.5rem;
    height: auto;
  }
  .itemName {
    color: black;
    font-size: 0.4rem;
  }
}

.notice-swipe {
  height: 40px;
  line-height: 40px;
}

.left {
  margin-right: 10px;
}

.noticeBar {
  border-bottom: 1px solid rgb(230, 230, 230);
  border-top: 1px solid rgb(230, 230, 230);
  padding: 0 10px;
  font-size: 0.35rem;
  height: 0.9rem;
  background: white;
  .notice-left-icon {
    width: 1.5rem;
    height: auto;
    margin-left: 10px;
  }

  a {
    color: rgb(31, 31, 31);
  }
}

.top {
  width: 100%;
  background-color: white;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
  .logo {
    width: 3rem;
    height: 1rem;
    display: flex;
    align-items: center;
    margin-right: 0.1rem;
    img {
      width: 100%;
      height: auto;
      margin-top: 0.2rem;
    }
  }
  .search {
    width: 70vw;
    height: 0.4rem;
    background-color: #f7f7f7;
    border-radius: 30px;
    padding: 0.05rem;
    padding-left: 0.6rem;
    margin-right: 0.2rem;
    font-size: 0.25rem;
    color: #bbb;
    text-align: left;
    line-height: 0.4rem;
    position: relative;
    .iconfont {
      width: 0.4rem;
      height: 0.4rem;
      position: absolute;
      left: 0.1rem;
      background-color: red;
      background: url(../assets/search.png);
      background-size: 100%;
    }
  }
}
</style>
